import { Module } from '@nestjs/common';
import { CatsModule } from './cats/cats.module';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { join } from 'node:path';
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
import { HasuraService } from './hasura.service';
import { AuthorsModule } from './authors/authors.module';
import { BooksModule } from './books/books.module';
import { TestModule } from './test/test.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import appConfig from './config/app.config';
@Module({
  imports: [
    CatsModule,
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      playground: false,
      autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
      sortSchema: true,
      introspection: true,
      context: ({ req, res }: Record<string, unknown>) => ({ req, res }),
      plugins: [ApolloServerPluginLandingPageLocalDefault()],
      // typePaths: ['./**/*.graphql'],
    }),
    ConfigModule.forRoot({
      isGlobal: true, // 让 ConfigService 在整个应用中可用
      load: [appConfig], // 加载自定义配置文件
    }),
    AuthorsModule,
    BooksModule,
    TestModule,
  ],
  controllers: [],
  providers: [HasuraService,ConfigService],
})
export class AppModule {}
